<?php
class workMod extends commonMod{

	public function index(){

 		if (empty($_SESSION['oa_id'])) {
 			$this->alert('您还没有登陆');
 		}

		// 历史的信息( 3*x+1 )
		$where   = " and `show`=1 and `recover`=0 and `addtime`<'".date('Y-m-d')."' and userid='".$_SESSION['oa_id']."' group by addtime";
		$histArr = __query("select * from {tabpre}workplan where 1 $where");
		if (!empty($histArr))
		{
			$histArrLen = count($histArr);
			$x = ceil(($histArrLen-1)/3);
			$total_hist_len = (3*$x)+1;

			$this->assign("histArrLen", $histArrLen);
			$this->assign("total_hist_len", $total_hist_len);
			$this->assign("histArr", $histArr);
		}


		$this->display();
	}
	public function add(){

 		$text = text_in($_POST['text']);
 		$addtime = text_in($_POST['addtime']);
 		if (!empty($addtime)){
 			$add_time = date('Y-m-d', strtotime($addtime));
 		}else{
 			$add_time = 'now()';
 		}

 		if (empty($_SESSION['oa_id'])) {
 			$this->alert('您还没有登陆');
 		}
 		if (empty($text)) {
 			$this->alert('内容不能为空');
 		}



		$sql = "insert into {tabpre}workplan (`userid`,`title`,`content`,`datetime`,`addtime`,`show`,`recover`)values('".$_SESSION['oa_id']."','$text','',$add_time,now(),1,0);";
		$arr = __query($sql);
		if (!empty($arr)){
			$this->alert('发布成功', '/work.do');
		}else{
			$this->alert('发布失败');
		}
		$this->assign("newsarr", $newsarr[0]);
		$this->display();
	}
}